#include "TcpClient.hpp"
#include <iostream>
#include "Sock.hpp"
#include "Protocal.hpp"
using namespace vic_protocol;

static void usage(std::string proc)
{
    std::cout << "Usage\n\t" << proc << "serverip serverport\n"
              << std::endl;
}
int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        usage(argv[0]);
        exit(USAGE_ERR);
    }
    std::string serverip = argv[1];
    uint16_t serverport = atoi(argv[2]);

    // 创建套接字
    Sock sock;
    sock.Socket();
    int n = sock.Connect(serverip, serverport);
    char buffer[1024];
    while (true)
    {
        Request req;
        std::cout << "data1# ";
        std::cin >> req._x;
        std::cout << "data2# ";
        std::cin >> req._y;
        std::cout << "op# ";
        std::cin >> req._op;

        // 序列化
        std::string sendString;
        req.Serialize(&sendString);
        //添加包头
        sendString=AddHeader(sendString);
        //发送
        send(sock.Fd(),sendString.c_str(),sendString.size(),0);
        //获取相应
        std::string package;
        int n=0;
        n=ReadPackage(sock.Fd(),buffer,&package);
    }

    return 0;
}